home *** CD-ROM | disk | FTP | other *** search
/ Singles Flirt Up Your Life! (German) / Singles Flirt Up Your Life.iso / data1.cab / Statemachine / fridge.lua < prev    next >
Text File  |  2004-01-29  |  6KB  |  178 lines

  1. -- fridge oldschool state machine
  2.  
  3. beginStateMachine()
  4.  
  5.     onMsg("buildMenu", function(msg)
  6.     
  7.         if (repairMenu()) then return end
  8.     
  9.         -- build the pie menu
  10.         clearPieMenu();
  11.         local button;
  12.         button = addPieMenuButton("pm_eatSnack", "eatSnack");
  13.         button.addDescription(ACTIVITY, "eatSnack");
  14. --        button = addPieMenuButton("pm_eatVegSnack", "eatVegSnack");
  15. --        button.addDescription(ACTIVITY, "eatVegSnack");
  16.         -- button.addIcon("guiIconHunger");
  17.         button = addPieMenuButton("pm_eatBreakfast", "eatBreakfast");
  18.         button.addDescription(ACTIVITY, "eatBreakfast");
  19.         button.addDescription(HIDE_IF_UNSELECTABLE, "true")
  20. --        button = addPieMenuButton("pm_eatSupper", "eatBreakfast");
  21. --        button.addDescription(ACTIVITY, "eatSupper");
  22.         button = addPieMenuButton("pm_eatDinner", "eatDinner");
  23.         button.addDescription(ACTIVITY, "eatDinner");
  24.         button.addDescription(HIDE_IF_UNSELECTABLE, "true")
  25.         -- button.addIcon("guiIconHunger");
  26.     end )
  27.  
  28.     -- open the fridge and eat a snack
  29.     onMsg("eatSnack", function(msg)
  30.         -- get the game object server
  31.         local gameObjectServer = getGameObjectServer();
  32.         -- get character who initiated this action
  33.         local character = getStateObjectFromID(msg.sender);
  34.         -- if this is broken: abort characters action
  35.         if abortIfBroken(character) then return end;        
  36.         -- walk to the closest action point
  37.         local actionPoint = character.getFreeActionPoint(this, "open");
  38.         -- get the walk state object
  39.         local wso = character.walkSO;
  40.         if (actionPoint) then
  41.             -- create state machine contexts
  42.             local wsoContext = StateMachineContext();
  43.             -- store the action point
  44.             wsoContext.storeData("actionPointName", actionPoint.getName());
  45.             wsoContext.storeData("snackCommand", "eatSnack");
  46.             if (wso.walkToActionPoint(actionPoint)) then
  47.                 wso.queueStateMachine("fridgeSnackChar.open", this, wsoContext);
  48.             else
  49.                 print("no path found");
  50.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  51.             end
  52.         else
  53.             print("no action point found");
  54.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  55.         end
  56.     end )
  57.     
  58.     
  59.     -- open the fridge and eat a snack
  60.     onMsg("eatVegSnack", function(msg)
  61.         -- get the game object server
  62.         local gameObjectServer = getGameObjectServer();
  63.         -- get character who initiated this action
  64.         local character = getStateObjectFromID(msg.sender);
  65.         -- if this is broken: abort characters action
  66.         if abortIfBroken(character) then return end;        
  67.         -- walk to the closest action point
  68.         local actionPoint = character.getFreeActionPoint(this, "open");
  69.         if (actionPoint) then
  70.             -- get the walk state object
  71.             local wso = character.walkSO;
  72.             -- create state machine contexts
  73.             local wsoContext = StateMachineContext();
  74.             -- store the action point
  75.             wsoContext.storeData("actionPointName", actionPoint.getName());
  76.             wsoContext.storeData("snackCommand", "eatVegSnack");
  77.             --wsoContext.storeData("snackCommand", "eatSnack");
  78.             if (wso.walkToActionPoint(actionPoint)) then
  79.                 wso.queueStateMachine("fridgeSnackChar.open", this, wsoContext);
  80.             else
  81.                 print("no path found");
  82.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  83.             end
  84.         else
  85.             print("no action point found");
  86.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  87.         end
  88.     end )
  89.     
  90.     
  91.     -- open the fridge and take breakfast
  92.     onMsg("eatBreakfast", function(msg)
  93.         -- get the game object server
  94.         local gameObjectServer = getGameObjectServer();
  95.         -- get character who initiated this action
  96.         local character = getStateObjectFromID(msg.sender);
  97.         -- if this is broken: abort characters action
  98.         if abortIfBroken(character) then return end;        
  99.         -- walk to the closest action point
  100.         local actionPoint = character.getFreeActionPoint(this, "open");
  101.         if (actionPoint) then
  102.             -- get the walk state object
  103.             local wso = character.walkSO;
  104.             -- create state machine contexts
  105.             local wsoContext = StateMachineContext();
  106.             -- store the action point
  107.             wsoContext.storeData("actionPointName", actionPoint.getName());
  108.             wsoContext.storeData("tabletType", "tabletBreakfast");
  109.             if (wso.walkToActionPoint(actionPoint)) then
  110.                 wso.queueStateMachine("fridgeTabletChar.open", this, wsoContext);
  111.             else
  112.                 print("no path found");
  113.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  114.             end
  115.         else
  116.             print("no action point found");
  117.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  118.         end
  119.     end )
  120.     
  121.     -- open the fridge and take dinner
  122.     onMsg("eatDinner", function(msg)
  123.         -- get the game object server
  124.         local gameObjectServer = getGameObjectServer();
  125.         -- get character who initiated this action
  126.         local character = getStateObjectFromID(msg.sender);
  127.         -- if this is broken: abort characters action
  128.         if abortIfBroken(character) then return end;        
  129.         -- walk to the closest action point
  130.         local actionPoint = character.getFreeActionPoint(this, "open");
  131.         if (actionPoint) then
  132.             -- get the walk state object
  133.             local wso = character.walkSO;
  134.             -- create state machine contexts
  135.             local wsoContext = StateMachineContext();
  136.             -- store the action point
  137.             wsoContext.storeData("actionPointName", actionPoint.getName());
  138.             wsoContext.storeData("tabletType", "tabletDinner");
  139.             if (wso.walkToActionPoint(actionPoint)) then
  140.                 wso.queueStateMachine("fridgeTabletChar.open", this, wsoContext);
  141.             else
  142.                 print("no path found");
  143.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  144.             end
  145.         else
  146.             print("no action point found");
  147.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  148.         end
  149.     end )
  150.     -- repair
  151.     onMsg("repair", function(msg)
  152.     
  153.         print("onMsg repair");
  154.         -- get character who initiated this action
  155.         local character = getStateObjectFromID(msg.sender);
  156.         -- walk to the closest action point
  157.         local actionPoint = character.getFreeActionPoint(this, "repair");
  158.         -- get the walk state object
  159.         local wso = character.walkSO;
  160.         if (actionPoint) then
  161.             -- create state machine contexts
  162.             local wsoContext = StateMachineContext();
  163.             -- store the action point
  164.             wsoContext.storeData("actionPointName", actionPoint.getName());
  165.             if (wso.walkToActionPoint(actionPoint)) then
  166.                 wso.queueStateMachine("repairChar.repairStart", this, wsoContext);
  167.             else
  168.                 print("no path found");
  169.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  170.             end
  171.         else
  172.             print("no action point found");
  173.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  174.         end
  175.     end )
  176.                 
  177. endStateMachine()
  178.